#!/usr/bin/env python3

import os
import rospy
import time
from std_msgs.msg import String, Int8

# Shuts down the system when the vehicle is turned off

def on_ignition_switch(msg):
    if msg.data <= 2:
        rospy.logwarn("vehicle turned off, shutting down in 10 seconds")
        time.sleep(10)
        os.system("shutdown -h now")

if __name__ == "__main__":
    rospy.init_node('shutdown_node')

    sub_ignition_switch = rospy.Subscriber('/vehicle/ignition_switch', Int8, on_ignition_switch)
    pub_speak = rospy.Publisher('/sound/speak', String, queue_size = 1)

    rospy.spin()
